package com.bigknow.appstore.web.base.vo;

import com.bigknow.appstore.web.framework.entity.IEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created by TwelveFoldEr on 2016/6/2.
 */
public class FancyTreeVo {
    private String key;
    private String title;
    private String type;
    private boolean folder;
    private boolean selected;
    /**
     * 隐藏checkbox
     */
    private boolean hideCheckbox;
    /**
     * 不可select（checkbox为灰色）
     */
    private boolean unselectable;

    private boolean expanded = false;
    private boolean lazy = false;
    private String icon;
    private Map<String,String> data = new HashMap<>();
    private List<FancyTreeVo> children = new ArrayList<>();

    public static <T extends IEntity> FancyTreeVo toFancyTreeVo(T entity, Consumer<FancyTreeVo> consumer) {
        FancyTreeVo result = new FancyTreeVo(entity.getId(), "");
        consumer.accept(result);
        return result;
    }

    public static <T extends IEntity> List<FancyTreeVo> toFancyTreeVo(List<T> entities, BiConsumer<T, FancyTreeVo> consumer) {
        List<FancyTreeVo> result = new ArrayList<>();
        entities.forEach(x -> {
            FancyTreeVo ftv = new FancyTreeVo(x.getId(), "");
            consumer.accept(x, ftv);
            result.add(ftv);
        });
        return result;
    }

    public Map<String,String> add(String key,String value){
        this.data.put(key,value);
        return data;
    }

    public FancyTreeVo(String key, String title) {
        this.key = key;
        this.title = title;
    }

    public FancyTreeVo(String key, String title, boolean unselectable, boolean hideCheckbox){
        this(key,title);
        this.unselectable = unselectable;
    }

    public FancyTreeVo(String key, String title, String type) {
        this.key = key;
        this.title = title;
        this.type = type;
    }

    public FancyTreeVo(String key, String title, String type, boolean unselectable, boolean hideCheckbox){
        this(key,title,type);
        this.unselectable = unselectable;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean getFolder() {
        return folder;
    }

    public void setFolder(boolean folder) {
        this.folder = folder;
    }

    public boolean getSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public List<FancyTreeVo> getChildren() {
        return children;
    }

    public void setChildren(List<FancyTreeVo> children) {
        this.children = children;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public boolean isExpanded() {
        return expanded;
    }

    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
    }

    public boolean getLazy() {
        return lazy;
    }

    public void setLazy(boolean lazy) {
        this.lazy = lazy;
    }

    public Map<String, String> getData() {
        return data;
    }

    public void setData(Map<String, String> data) {
        this.data = data;
    }

    public boolean isUnselectable() {
        return unselectable;
    }

    public void setUnselectable(boolean unselectable) {
        this.unselectable = unselectable;
    }

    public boolean isHideCheckbox() {
        return hideCheckbox;
    }

    public void setHideCheckbox(boolean hideCheckbox) {
        this.hideCheckbox = hideCheckbox;
    }
}
